<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>getElementById</title>
</head>

<body>
    <div id="test">打开控制台查看结果</div>
    <script>
        const getElementById = (id) => {
            if (document?.all?.length) {
                return document.all[id];
            } else {
                return null;
            }
        }
        const test = getElementById('test');
        test.style.color = '#24b0e1';
        console.log(test)
    </script>
</body>

</html>